import { Column, Entity, OneToMany } from 'typeorm';
import { BaseEntity } from './BaseEntity';
import { SysRoleUser } from './SysRoleUser';
import { SysDepartmentUser } from './SysDepartmentUser';

@Entity()
export class SysUser extends BaseEntity {
  @Column({
    type: 'varchar',
    comment: '账号'
  })
  account: string;

  @Column({
    type: 'varchar',
    comment: '用户所属平台',
    nullable: true,
    name: 'client_id'
  })
  clientId: string;

  @Column({
    type: 'varchar',
    comment: '用户所属平台名称',
    nullable: true,
    name: 'client_name'
  })
  clientName: string;

  @Column({
    type: 'varchar',
    nullable: true,
    comment: '用户名'
  })
  name: string;

  @Column({
    type: 'varchar',
    nullable: true,
    comment: '手机号'
  })
  phone: string;

  @Column({
    type: 'varchar',
    nullable: true,
    comment: '手机验证码'
  })
  code: string;

  @Column({
    type: 'int',
    default: 0,
    comment: '账号状态(0:正常;1:冻结)'
  })
  status: number;

  @Column({
    default: false,
    type: 'boolean',
    comment: '是否禁用'
  })
  forbidden: boolean;

  @Column({
    type: 'varchar',
    comment: '密码',
    select: false,
    nullable: true
  })
  password: string;

  @Column({
    type: 'varchar',
    comment: '密码加盐标识',
    nullable: true
  })
  salt: string;

  @Column({
    type: 'varchar',
    comment: '是否在线',
    default: false
  })
  online: boolean;

  @OneToMany(() => SysRoleUser, s => s.SysUserId)
  SysRoleUser: SysRoleUser[];

  @OneToMany(() => SysDepartmentUser, s => s.SysUserId)
  SysDepartmentUser: SysDepartmentUser[];
}
